/**
 * 引入接口地址
 */
const appUrls = require('../interface/interface')
//const appHOST = 'http://saas2.demo.qiyebox.com'
const appHOST = 'http://eboxh5.app:5000'
// 错误处理
const handleError = function (error) {
    console.log(error)
}
//请求头
const headers = {}
//默认请求方式
const init = {
    method: 'POST',
    credentials: 'include'
}
//模拟表单数据
export function formatData(data) {
    let _data = new FormData();
    for (let key in data) {
        _data.append(key, typeof data[key] === 'string'?data[key].trim():data[key]);
    }
    return _data;
}

//Banner,logo,备案号
export async function fetchLogo() {
    try {
        const logo = await fetch(appHOST + appUrls.publicInterface.getLogo, {
            ...init
        })
        return logo.json()
    } catch (error) {
        handleError(error)
    }
}
//长租列表
export async function fetchLongRentList({
    page = 1
}) {
    try {
        const longRentList = await fetch(appHOST + appUrls.longRentInterface.list, {
            ...init,
            body: formatData({page})
        })
        return longRentList.json()
    } catch (error) {
        handleError(error)
    }
}
//短租列表
export async function fetchShortRentList({page}) {
    try {
        const shortRentList = await fetch(appHOST + appUrls.shortRentInterface.getStationListVO, {
            ...init,
            body: formatData({page})
        })
        return shortRentList.json()
    } catch (error) {
        handleError(error)
    }

}

//会议室列表
export async function fetchMeetingRoomList({page}) {
    try {
        const meetingRoomList = await fetch(appHOST + appUrls.meetingRoomInterface.listByPage, {
            ...init,
            body: formatData({page})
        })
        return meetingRoomList.json()
    } catch (error) {
        handleError(error)
    }
}
// 场地列表
export async function fetchSiteList({page}) {
    try {
        const siteList = await fetch(appHOST + appUrls.siteInterface.placeList, {
            ...init,
            body: formatData({page})
        })
        return siteList.json()
    } catch (error) {
        handleError(errro)
    }
}
// 专题模块
export async function fetchModules(body = null) {
    try {
        const modules = await fetch(appHOST + appUrls.themeInterface.getModules, {
            ...init
        })
        return modules.json()
    } catch (e) {
        handleError(e)
    }
}
// 公告列表
export async function fetchAnnouncementList({pageNum=1}) {
    try {
        const announceMentList = await fetch(appHOST + appUrls.themeInterface.getAnnouncementList, {
            ...init,
            body: formatData({pageNum})
        })
        return announceMentList.json()
    } catch (error) {
        handleError(error)
    }
}

// 任务发布
export async function fetchDemandList(body = null) {
    try {
        const demandList = await fetch(appHOST + appUrls.themeInterface.getSpecialTaskList, {
            ...init,
            body: formatData(body)
        })
        return demandList.json()
    } catch (error) {
        handleError(error)
    }
}
// 投融资咨询
export async function fetchConsultingList(body = null) {
    try {
        const consultingList = await fetch(appHOST + appUrls.themeInterface.getInvestList, {
            ...init,
            body: formatData(body)
        })
        return consultingList.json()
    } catch (error) {
        handleError(error)
    }
}
// 路演
export async function fetchRoadShowList(body = null) {
    try {
        const roadShowList = await fetch(appHOST + appUrls.themeInterface.getRoadShowList, {
            ...init,
            body: formatData(body)
        })
        return roadShowList.json()
    } catch (error) {
        handleError(error)
    }
}
// 社群列表
export async function fetchGroupList(body = null) {
    try {
        const groupList = await fetch(appHOST + appUrls.themeInterface.getRecruitList, {
            ...init,
            body: formatData(body)
        })
        return groupList.json()
    } catch (error) {
        handleError(error)
    }
}
/**
 * @description  获取企业展示 showType=1 获取服务商展示 showtype=2 获取投融资展示 showtype=3
 * @param  {} {type=1}
 */
export async function fetchShowMain({showType = 1}) {
    try {
        const showMainList = await fetch(appHOST + appUrls.themeInterface.getShowMainList, {
            ...init,
            body: formatData({showType})
        })
        return showMainList.json()
    } catch (error) {
        handleError(error)
    }
}